package com.baymax.test.scene.demo

import android.graphics.Rect
import android.graphics.RectF
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import com.badlogic.gdx.graphics.Color
import com.baymax.test.scene.BaseGroupScene
import com.baymax.test.scene.addButton
import com.baymax.test.scene.addDFView
import com.baymax.test.scene.addText
import com.baymax.test.scene.newSceneFlexContainer
import com.google.common.collect.Multimaps.index
import org.http4k.filter.TraceId.Companion.new
import kotlin.properties.Delegates

class WKAnimatorScene : BaseGroupScene() {

    override fun onCreateView(
        p0: LayoutInflater,
        p1: ViewGroup,
        p2: Bundle?
    ): ViewGroup = p1.newSceneFlexContainer {
        val r = Rect()
        val vg = LinearLayout(requireSceneContext())
        vg.orientation = LinearLayout.VERTICAL
        repeat(20) {
            vg.addText("Hello ,Title $it")
        }

        addDFView(300, 900, vg) {
            vg.setPadding(10, 10, 10, 10)
            vg.minimumWidth = 200
            vg.dividerPadding = 10
        }
        val draw = WkAnimatorDrawable()
        vg.background = draw
        val rect = Rect()
        vg.post {
            draw.setMainDrawable(ColorDrawable(0x66ff00ff))
            val c = vg.getChildAt(0)
            draw.mountToView(c)
        }
        var index: Int by Delegates.observable(0) { p, o, n ->
          draw.moveToView(vg.getChildAt(n))
        }
        index = 1

        fun reset() {
            index = 0
        }

        fun up() {
            index = index.minus(1).coerceAtLeast(0)
        }

        fun down() {
            index = index.plus(1).coerceAtMost(19)
        }
        addButton("up") {
            up()
        }
        addButton("down") {
            down()
        }
        addButton("reset") {
            reset()
        }
    }
}